package com.baseLearn.learn.iterator.map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class TestMap {



    public static void main(String[] args) {
        HashMap<String, String> hMap = getMap();

        //1.获取map的key的set型集合,再循环
        for (String map : hMap.keySet()) {
            System.out.println("key=" + map + ",value=" + hMap.get(map));
        }

        //2.获取map的SET集合(内部结构为key,value)
        for (Map.Entry<String, String> map : hMap.entrySet()) {
            System.out.println("key=" + map.getKey() + ",value=" + map.getValue());
        }

        //3.利用迭代器
        Iterator<Map.Entry<String, String>> iterator = hMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, String> entry = iterator.next();
            System.out.println("key=" + entry.getKey() + ",value=" + entry.getValue());
        }


    }


    public static HashMap<String, String> getMap() {
        HashMap<String, String> hashmap = new HashMap<>();
        hashmap.put("1", "h");
        hashmap.put("2", "e");
        hashmap.put("3", "l");
        hashmap.put("4", "l");
        hashmap.put("5", "w");
        hashmap.put("6", "o");
        hashmap.put("7", "r");
        hashmap.put("8", "l");
        hashmap.put("9", "d");
        return hashmap;
    }
}